<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE HTML>
<script type="text/javascript" src="assets/js/jquery-1.10.2.min.js"></script>
<link href="static/lib/icheck/icheck.css" rel="stylesheet" type="text/css"/>
<link href="static/lib/css/H-ui.min.css" rel="stylesheet" type="text/css"/>
<link href="static/lib/css/H-ui.admin.css" rel="stylesheet" type="text/css"/>
<link href="static/lib/css/skin.css" rel="stylesheet" type="text/css"/>
<link href="static/lib/Hui-iconfont/1.0.1/iconfont.css" rel="stylesheet" type="text/css"/>
<link href="static/lib/icheck/icheck.css" rel="stylesheet" type="text/css"/>

<html>
<head>
<title>规则列表</title>
</head>
<body>
<div class="pd-10">
    <div class="cl pd-5 bk-gray mt-10">
        <form action="rule/newrules/list" method="get" id="listForm">
            <input type="hidden" id="createUser" value="${account.user_id}" name="createUser">
            <input type="hidden" name="page" value="1"/>
            <input type="hidden" value="${flag}" id="flag"/>
            <table style="border-collapse:separate; border-spacing:0px 10px; margin-top: -10px;">
                <tr>
                    <td>省份&nbsp;&nbsp;&nbsp;</td>
                    <td style="width: 150px">
                        <select id="province" class="input-text" name="province"
                                style="width: 200px;height:30px;margin-right: 15px;">
                            <option value="-1">请选择</option>
                        </select>
                    </td>
                    <td>城市&nbsp;&nbsp;&nbsp;</td>
                    <td style="width: 150px">
                        <select id="city" class="input-text" name="city"
                                style="width: 200px;height:30px;margin-right: 15px;">
                            <option value="-1">请选择</option>
                        </select>
                    </td>
                    <td>商家&nbsp;&nbsp;&nbsp;</td>
                    <td style="width: 150px">
                        <select id="supplierCode" class="input-text" name="supplierCode"
                                style="width: 200px;height:30px;margin-right: 15px;">
                            <option value="-1">请选择</option>
                        </select>
                    </td>
                    <td>承运商&nbsp;&nbsp;</td>
                    <td style="width: 150px">
                        <select id="carrierCode" class="input-text" name="carrierCode"
                                style="width: 200px;height:30px;margin-right: 15px;">
                            <option value="-1">请选择</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <%--<td></td>
                    <td>
                        <a href="rule/newrules/add/view" class="ml-5 btn btn-success" style="text-decoration: none;">新增</a>
                    </td>
                    <td></td>
                    <td>
                        <a href="rule/newrules/import/view" class="ml-5 btn btn-success" style="text-decoration: none;">批量导入</a>
                    </td>
                    <td></td>--%>
                    <td>
                        <button type="button" class="btn btn-success radius" id="search" name="">
                            查询
                        </button>
                    </td>
                </tr>
            </table>
        </form>
    </div>
    <div class="mt-10">
        <table
                class="table table-border table-bordered table-hover table-bg table-sort">
            <thead>
            <tr class="text-c">
                <th width="3%">序号</th>
                <th width="5%">省份</th>
                <th width="5%">城市</th>
                <th width="10%">商家</th>
                <th width="10%">承运商</th>
                <th width="4%">区间类型</th>
                <th width="4%">区域级别</th>
                <th width="4%">价格类型</th>
                <th width="4%">发货城市</th>
                <th width="4%">代收款</th>
                <th width="4%">组包</th>
                <th width="4%">上门退换</th>
                <th width="4%">当日达</th>
                <th width="4%">冷链</th>
                <th width="4%">菜鸟驿站</th>
                <%--<th width="10%">操作</th>--%>
            </tr>
            </thead>
            <tbody id="view">
            </tbody>
        </table>
    </div>
    <div class="mt-10" id="page" style="text-align: right;"></div>
</div>
<script id="demo" type="text/html">
    {{# for(var i = 0, len = d.list.length; i < len; i++){ }}
    {{# var l = d.list[i]}}
    <tr class="text-c text-m">
        <th>{{i + 1}}</th>
        <th>{{l.toProvinceName}}</th>
        <th>{{l.toCityName}}</th>
        <th>{{l.supplierName}}</th>
        <th>{{l.carrierName}}</th>
        <th>{{l.ruleType}}</th>
        <th>{{l.regionName}}</th>
        <th>{{l.settlementTypeDesc}}</th>
        <th>{{l.fromCityName}}</th>
        <th>{{l.codFlag}}</th>
        <th>{{l.isCombinedFlag}}</th>
        <th>{{l.directionFlag}}</th>
        <th>{{l.expressScheduleTypeFlag}}</th>
        <th>{{l.temperatureFlag}}</th>
        <th>{{l.cainiaoFlag}}</th>
        <%--<th>
            <a href="rule/newrules/edit/view?ruleId={{l.ruleId}}"
               class="ml-5 btn btn-success" style="text-decoration: none;">编辑</a>
            <a href="rule/newrules/copy/view?ruleId={{l.ruleId}}"
               class="ml-5 btn btn-success" style="text-decoration: none;">复制</a>
        </th>--%>
    </tr>
    {{# } }}
</script>
<script type="text/javascript" src="static/lib/layer/laytpl.js"></script>
<script type="text/javascript" src="static/lib/layer/layer.js"></script>
<script type="text/javascript" src="static/lib/laypage/laypage.js"></script>
<script type="text/javascript" src="static/lib/Validform/Validform.min.js"></script>
<script type="text/javascript" src="static/local/index.js?v=1.0.0"></script>
<script type="text/javascript">
    $(function () {
        var flag = $("#flag").val();
        var i,j,m = 0;
        if (flag == 1) {
            alert("未查询到相关数据");
        }

        $.ajax({
            type: "POST",
            cache: false,
            async: false,
            url: "rule/newrules/selectList",
            data: {
            },
            dataType: 'json',
            success: function (result) {
                var data = result.data;

                if( data.regionList.length > 0 ){
                    for ( i = 0 ; i < data.regionList.length; i++) {
                        $("<option value='" + data.regionList[i].code + "'>" + data.regionList[i].name + "</option>").appendTo("#province");
                    }
                }
                if( data.supplierList.length > 0 ){
                    for ( j = 0; j < data.supplierList.length; j++) {
                        $("<option value='" + data.supplierList[j].code + "'>" + data.supplierList[j].name + "</option>").appendTo("#supplierCode");
                    }
                }
                if( data.carrierList.length > 0 ){
                    for ( m = 0; m < data.carrierList.length; m++) {
                        $("<option value='" + data.carrierList[m].carrierCode + "'>" + data.carrierList[m].carrierName + "</option>").appendTo("#carrierCode");
                    }
                }

            },
            error: function (result) {
                layer.msg("网络错误，请稍候重试", {icon: 5, time: 1000});
            }
        });


        $("#province").change(function () {
            var province = $(this).val();
            $("#city").css("display", "block").find("option").remove();
            $("#city").html("<option value='-1'>请选择</option>");
            $.ajax({
                type: "POST",
                cache: false,
                async: false,
                url: "rule/newrules/cityRegionList",
                data: {
                    provinceCode: province
                },
                dataType: 'json',
                success: function (result) {
                    var data = result.data;
                    if (data.cityRegionList.length > 0) {
                        for (var i = 0; i < data.cityRegionList.length; i++) {
                            $("<option value='" + data.cityRegionList[i].code + "'>" + data.cityRegionList[i].name + "</option>").appendTo("#city");
                        }
                    } else {
                        layer.msg("未查询到所选省份下的城市信息", {icon: 5, time: 1000});
                    }

                },
                error: function (result) {
                    layer.msg("网络错误，请稍候重试", {icon: 5, time: 1000});
                }
            });
        });

        $("#listForm").attr("action", "rule/newrules/list");

        initPage("listForm", "demo", "view", "page");

    });

    $("#search").click(function () {
        $("#listForm").attr("action", "rule/newrules/list");
        $("[name='page']").val(1);
        if (!checkTime("begin", "end")) {
            return;
        }
        initPage("listForm", "demo", "view", "page");
        getSelectInfo();
    });

    function getSelectInfo() {
        $.ajax({
            type: "POST",
            cache: false,
            async: false,
            url: "rule/newrules/selectList",
            data: {
            },
            dataType: 'json',
            success: function (result) {
                var data = result.data;
                if (data.length > 0) {
                    if( data.regionList.length > 0 ){
                        for (var i = 0 ; i < data.regionList.length; i++) {
                            $("<option value='" + data.regionList[i].code + "'>" + data.regionList[i].name + "</option>").appendTo("#province");
                        }
                    }
                    if( data.supplierList.length > 0 ){
                        for ( var j = 0; j < data.supplierList.length; j++) {
                            $("<option value='" + data.supplierList[j].code + "'>" + data.supplierList[j].name + "</option>").appendTo("#supplierCode");
                        }
                    }
                    if( data.carrierList.length > 0 ){
                        for ( var m = 0; m < data.carrierList.length; m++) {
                            $("<option value='" + data.carrierList[m].carrierCode + "'>" + data.carrierList[m].carrierName + "</option>").appendTo("#carrierCode");
                        }
                    }
                }
            },
            error: function (result) {
                layer.msg("网络错误，请稍候重试", {icon: 5, time: 1000});
            }
        })
    }
</script>
</body>
</html>